#include "Poco/Stopwatch.h"
#include "StopWatch.h"

using namespace SystemTool;

// Construct the stop watch
StopWatch::StopWatch()
{
    m_pStopWatch = new Poco::Stopwatch;
}

// Destruct the stop watch
StopWatch::~StopWatch()
{
    if(m_pStopWatch)
    {
        delete (Poco::Stopwatch*)m_pStopWatch;
        m_pStopWatch = nullptr;
    }
}

// Start the stop watch
void StopWatch::Start()
{
    if(m_pStopWatch)
    {
        ((Poco::Stopwatch*)m_pStopWatch)->start();
    }
}

// Stop the stop watch
void StopWatch::Stop()
{
    if(m_pStopWatch)
    {
        ((Poco::Stopwatch*)m_pStopWatch)->stop();
    }
}

// Restart the stop watch
void StopWatch::Restart()
{
    if(m_pStopWatch)
    {
        ((Poco::Stopwatch*)m_pStopWatch)->restart();
    }
}

// Get elaspsed time
long long StopWatch::GetElaspsed_Us()
{
    if(m_pStopWatch)
    {
        return ((Poco::Stopwatch*)m_pStopWatch)->elapsed();
    }
    return 0;
}

// Get elaspsed time
long long StopWatch::GetElaspsed_Ms()
{
    return GetElaspsed_Us() / 1000;
}

// Get elaspsed time
long long StopWatch::GetElaspsed_S()
{
    return GetElaspsed_Ms() / 1000;
}
